<template>
  <el-dialog :close-on-click-modal="false" v-drag :title="$t('查看详情')" :v-if="dialogVisible" :visible.sync="dialogVisible" width="900px" top="10vh" @close="close">
    <div class="dialogContentBox">
      <el-form ref="form" :model="record" label-width="100px" :rules="rules" label-position="left" style="margin:0 30px;">
        <el-form-item :label="$t('名称')" prop="name">
          {{ record.show_name }}
        </el-form-item>
        <el-form-item :label="$t('描述')" prop="des">
          {{ record.des }}
        </el-form-item>
        <el-form-item :label="$t('模板类型')" prop="type">
          {{ $t(typeList[record.type]) }}
        </el-form-item>
        <el-form-item :label="$t('分组依据')" prop="group">
          {{ $t(groupList[record.type][record.group]) }}
        </el-form-item>
        <el-form-item :label="$t('查询条件')" prop="group"> </el-form-item>
      </el-form>
      <TempleEdit type="info" :select="record.select" />
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="close">{{ $t("取 消") }}</el-button>
    </span>
  </el-dialog>
</template>
<script>
import TempleEdit from "./TempleEdit";
export default {
  name: "TempleDetails",
  components: {
    TempleEdit
  },
  data() {
    return {
      dialogVisible: false,
      record: {
        name: "",
        des: "",
        type: "attack-defense",
        group: "sip",
        select: {
          condition_list: []
        }
      },
      recordCopy: {
        name: "",
        des: "",
        type: "attack-defense",
        group: "sip",
        select: {
          condition_list: []
        }
      },
      typeList: {
        "attack-defense": "异常报文攻击",
        "ddos-defense": "DDOS攻击",
        "av-defense": "病毒防御",
        "content-filter": "工业审计",
        "ips-defense": "入侵防御",
        "event-type": "事件类型",
        "protocol-type": "协议类型"
      },
      groupList: {
        "attack-defense": {
          sip: "攻击源地址",
          dip: "受攻击主机",
          "event-type": "威胁攻击",
          l4type: "受影响协议"
        },
        "ddos-defense": {
          dip: "受攻击主机"
        },
        "av-defense": {
          sip: "攻击源地址",
          dip: "受攻击主机",
          "event-type": "威胁攻击",
          l4type: "受影响协议"
        },
        "content-filter": {
          sip: "源地址",
          dip: "目的地址",
          "event-type": "工业事件",
          l4type: "工业协议"
        },
        "ips-defense": {
          sip: "攻击源地址",
          dip: "受攻击主机",
          "event-type": "威胁攻击",
          l4type: "受影响协议"
        },
        "event-type": {
          "event-type": "威胁攻击"
        },
        "protocol-type": {
          l4type: "受影响协议"
        }
      },
      connectorList: {
        and: "与",
        or: "或"
      },
      keyList: {
        sip: "源IP",
        dip: "目的IP",
        sport: "源端口",
        dport: "目的端口"
      },
      operatorList: {
        equal: "等于",
        unequal: "不等于"
      },
      rules: {}
    };
  },
  methods: {
    init(data) {
      this.dialogVisible = true;
      if (data) {
        const temp = {
          ...data,
          select:{
            condition_list:data.condition_list
          }
        }
        this.record = Object.assign(this.record, temp);
      }
    },
    close() {
      this.dialogVisible = false;
      this.type = null;
      this.record = JSON.parse(JSON.stringify(this.recordCopy));
      this.$refs.form.resetFields();
    }
  }
};
</script>
<style scoped>
.dialogContentBox {
  max-height: calc(80vh - 184px);
  overflow-y: auto;
}
.temple-details-table:not(:first-child) {
  margin-top: 24px;
}
</style>
